<?php


abstract class BaseRechner extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $standort_id = 0;


	
	protected $benutzer_id = 0;


	
	protected $bezeichnung;


	
	protected $bemerkung;


	
	protected $updated_on;

	
	protected $aStandort;

	
	protected $aBenutzer;

	
	protected $collArbeitsplatznutzerHasRechners;

	
	protected $lastArbeitsplatznutzerHasRechnerCriteria = null;

	
	protected $collRechnerHasSoftwares;

	
	protected $lastRechnerHasSoftwareCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getStandortId()
	{

		return $this->standort_id;
	}

	
	public function getBenutzerId()
	{

		return $this->benutzer_id;
	}

	
	public function getBezeichnung()
	{

		return $this->bezeichnung;
	}

	
	public function getBemerkung()
	{

		return $this->bemerkung;
	}

	
	public function getUpdatedOn($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_on === null || $this->updated_on === '') {
			return null;
		} elseif (!is_int($this->updated_on)) {
						$ts = strtotime($this->updated_on);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_on] as date/time value: " . var_export($this->updated_on, true));
			}
		} else {
			$ts = $this->updated_on;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = RechnerPeer::ID;
		}

	} 
	
	public function setStandortId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->standort_id !== $v || $v === 0) {
			$this->standort_id = $v;
			$this->modifiedColumns[] = RechnerPeer::STANDORT_ID;
		}

		if ($this->aStandort !== null && $this->aStandort->getId() !== $v) {
			$this->aStandort = null;
		}

	} 
	
	public function setBenutzerId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->benutzer_id !== $v || $v === 0) {
			$this->benutzer_id = $v;
			$this->modifiedColumns[] = RechnerPeer::BENUTZER_ID;
		}

		if ($this->aBenutzer !== null && $this->aBenutzer->getId() !== $v) {
			$this->aBenutzer = null;
		}

	} 
	
	public function setBezeichnung($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->bezeichnung !== $v) {
			$this->bezeichnung = $v;
			$this->modifiedColumns[] = RechnerPeer::BEZEICHNUNG;
		}

	} 
	
	public function setBemerkung($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->bemerkung !== $v) {
			$this->bemerkung = $v;
			$this->modifiedColumns[] = RechnerPeer::BEMERKUNG;
		}

	} 
	
	public function setUpdatedOn($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_on] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_on !== $ts) {
			$this->updated_on = $ts;
			$this->modifiedColumns[] = RechnerPeer::UPDATED_ON;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->standort_id = $rs->getInt($startcol + 1);

			$this->benutzer_id = $rs->getInt($startcol + 2);

			$this->bezeichnung = $rs->getString($startcol + 3);

			$this->bemerkung = $rs->getString($startcol + 4);

			$this->updated_on = $rs->getTimestamp($startcol + 5, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 6; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Rechner object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(RechnerPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			RechnerPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isModified() && !$this->isColumnModified(RechnerPeer::UPDATED_ON))
    {
      $this->setUpdatedOn(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(RechnerPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aStandort !== null) {
				if ($this->aStandort->isModified()) {
					$affectedRows += $this->aStandort->save($con);
				}
				$this->setStandort($this->aStandort);
			}

			if ($this->aBenutzer !== null) {
				if ($this->aBenutzer->isModified()) {
					$affectedRows += $this->aBenutzer->save($con);
				}
				$this->setBenutzer($this->aBenutzer);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = RechnerPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += RechnerPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collArbeitsplatznutzerHasRechners !== null) {
				foreach($this->collArbeitsplatznutzerHasRechners as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collRechnerHasSoftwares !== null) {
				foreach($this->collRechnerHasSoftwares as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aStandort !== null) {
				if (!$this->aStandort->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aStandort->getValidationFailures());
				}
			}

			if ($this->aBenutzer !== null) {
				if (!$this->aBenutzer->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aBenutzer->getValidationFailures());
				}
			}


			if (($retval = RechnerPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collArbeitsplatznutzerHasRechners !== null) {
					foreach($this->collArbeitsplatznutzerHasRechners as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collRechnerHasSoftwares !== null) {
					foreach($this->collRechnerHasSoftwares as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = RechnerPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getStandortId();
				break;
			case 2:
				return $this->getBenutzerId();
				break;
			case 3:
				return $this->getBezeichnung();
				break;
			case 4:
				return $this->getBemerkung();
				break;
			case 5:
				return $this->getUpdatedOn();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = RechnerPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getStandortId(),
			$keys[2] => $this->getBenutzerId(),
			$keys[3] => $this->getBezeichnung(),
			$keys[4] => $this->getBemerkung(),
			$keys[5] => $this->getUpdatedOn(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = RechnerPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setStandortId($value);
				break;
			case 2:
				$this->setBenutzerId($value);
				break;
			case 3:
				$this->setBezeichnung($value);
				break;
			case 4:
				$this->setBemerkung($value);
				break;
			case 5:
				$this->setUpdatedOn($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = RechnerPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setStandortId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setBenutzerId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setBezeichnung($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setBemerkung($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setUpdatedOn($arr[$keys[5]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(RechnerPeer::DATABASE_NAME);

		if ($this->isColumnModified(RechnerPeer::ID)) $criteria->add(RechnerPeer::ID, $this->id);
		if ($this->isColumnModified(RechnerPeer::STANDORT_ID)) $criteria->add(RechnerPeer::STANDORT_ID, $this->standort_id);
		if ($this->isColumnModified(RechnerPeer::BENUTZER_ID)) $criteria->add(RechnerPeer::BENUTZER_ID, $this->benutzer_id);
		if ($this->isColumnModified(RechnerPeer::BEZEICHNUNG)) $criteria->add(RechnerPeer::BEZEICHNUNG, $this->bezeichnung);
		if ($this->isColumnModified(RechnerPeer::BEMERKUNG)) $criteria->add(RechnerPeer::BEMERKUNG, $this->bemerkung);
		if ($this->isColumnModified(RechnerPeer::UPDATED_ON)) $criteria->add(RechnerPeer::UPDATED_ON, $this->updated_on);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(RechnerPeer::DATABASE_NAME);

		$criteria->add(RechnerPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setStandortId($this->standort_id);

		$copyObj->setBenutzerId($this->benutzer_id);

		$copyObj->setBezeichnung($this->bezeichnung);

		$copyObj->setBemerkung($this->bemerkung);

		$copyObj->setUpdatedOn($this->updated_on);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getArbeitsplatznutzerHasRechners() as $relObj) {
				$copyObj->addArbeitsplatznutzerHasRechner($relObj->copy($deepCopy));
			}

			foreach($this->getRechnerHasSoftwares() as $relObj) {
				$copyObj->addRechnerHasSoftware($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new RechnerPeer();
		}
		return self::$peer;
	}

	
	public function setStandort($v)
	{


		if ($v === null) {
			$this->setStandortId('null');
		} else {
			$this->setStandortId($v->getId());
		}


		$this->aStandort = $v;
	}


	
	public function getStandort($con = null)
	{
				include_once 'lib/model/om/BaseStandortPeer.php';

		if ($this->aStandort === null && ($this->standort_id !== null)) {

			$this->aStandort = StandortPeer::retrieveByPK($this->standort_id, $con);

			
		}
		return $this->aStandort;
	}

	
	public function setBenutzer($v)
	{


		if ($v === null) {
			$this->setBenutzerId('null');
		} else {
			$this->setBenutzerId($v->getId());
		}


		$this->aBenutzer = $v;
	}


	
	public function getBenutzer($con = null)
	{
				include_once 'lib/model/om/BaseBenutzerPeer.php';

		if ($this->aBenutzer === null && ($this->benutzer_id !== null)) {

			$this->aBenutzer = BenutzerPeer::retrieveByPK($this->benutzer_id, $con);

			
		}
		return $this->aBenutzer;
	}

	
	public function initArbeitsplatznutzerHasRechners()
	{
		if ($this->collArbeitsplatznutzerHasRechners === null) {
			$this->collArbeitsplatznutzerHasRechners = array();
		}
	}

	
	public function getArbeitsplatznutzerHasRechners($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseArbeitsplatznutzerHasRechnerPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collArbeitsplatznutzerHasRechners === null) {
			if ($this->isNew()) {
			   $this->collArbeitsplatznutzerHasRechners = array();
			} else {

				$criteria->add(ArbeitsplatznutzerHasRechnerPeer::RECHNER_ID, $this->getId());

				ArbeitsplatznutzerHasRechnerPeer::addSelectColumns($criteria);
				$this->collArbeitsplatznutzerHasRechners = ArbeitsplatznutzerHasRechnerPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ArbeitsplatznutzerHasRechnerPeer::RECHNER_ID, $this->getId());

				ArbeitsplatznutzerHasRechnerPeer::addSelectColumns($criteria);
				if (!isset($this->lastArbeitsplatznutzerHasRechnerCriteria) || !$this->lastArbeitsplatznutzerHasRechnerCriteria->equals($criteria)) {
					$this->collArbeitsplatznutzerHasRechners = ArbeitsplatznutzerHasRechnerPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastArbeitsplatznutzerHasRechnerCriteria = $criteria;
		return $this->collArbeitsplatznutzerHasRechners;
	}

	
	public function countArbeitsplatznutzerHasRechners($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseArbeitsplatznutzerHasRechnerPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(ArbeitsplatznutzerHasRechnerPeer::RECHNER_ID, $this->getId());

		return ArbeitsplatznutzerHasRechnerPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addArbeitsplatznutzerHasRechner(ArbeitsplatznutzerHasRechner $l)
	{
		$this->collArbeitsplatznutzerHasRechners[] = $l;
		$l->setRechner($this);
	}


	
	public function getArbeitsplatznutzerHasRechnersJoinArbeitsplatznutzer($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseArbeitsplatznutzerHasRechnerPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collArbeitsplatznutzerHasRechners === null) {
			if ($this->isNew()) {
				$this->collArbeitsplatznutzerHasRechners = array();
			} else {

				$criteria->add(ArbeitsplatznutzerHasRechnerPeer::RECHNER_ID, $this->getId());

				$this->collArbeitsplatznutzerHasRechners = ArbeitsplatznutzerHasRechnerPeer::doSelectJoinArbeitsplatznutzer($criteria, $con);
			}
		} else {
									
			$criteria->add(ArbeitsplatznutzerHasRechnerPeer::RECHNER_ID, $this->getId());

			if (!isset($this->lastArbeitsplatznutzerHasRechnerCriteria) || !$this->lastArbeitsplatznutzerHasRechnerCriteria->equals($criteria)) {
				$this->collArbeitsplatznutzerHasRechners = ArbeitsplatznutzerHasRechnerPeer::doSelectJoinArbeitsplatznutzer($criteria, $con);
			}
		}
		$this->lastArbeitsplatznutzerHasRechnerCriteria = $criteria;

		return $this->collArbeitsplatznutzerHasRechners;
	}

	
	public function initRechnerHasSoftwares()
	{
		if ($this->collRechnerHasSoftwares === null) {
			$this->collRechnerHasSoftwares = array();
		}
	}

	
	public function getRechnerHasSoftwares($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseRechnerHasSoftwarePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collRechnerHasSoftwares === null) {
			if ($this->isNew()) {
			   $this->collRechnerHasSoftwares = array();
			} else {

				$criteria->add(RechnerHasSoftwarePeer::RECHNER_ID, $this->getId());

				RechnerHasSoftwarePeer::addSelectColumns($criteria);
				$this->collRechnerHasSoftwares = RechnerHasSoftwarePeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(RechnerHasSoftwarePeer::RECHNER_ID, $this->getId());

				RechnerHasSoftwarePeer::addSelectColumns($criteria);
				if (!isset($this->lastRechnerHasSoftwareCriteria) || !$this->lastRechnerHasSoftwareCriteria->equals($criteria)) {
					$this->collRechnerHasSoftwares = RechnerHasSoftwarePeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastRechnerHasSoftwareCriteria = $criteria;
		return $this->collRechnerHasSoftwares;
	}

	
	public function countRechnerHasSoftwares($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseRechnerHasSoftwarePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(RechnerHasSoftwarePeer::RECHNER_ID, $this->getId());

		return RechnerHasSoftwarePeer::doCount($criteria, $distinct, $con);
	}

	
	public function addRechnerHasSoftware(RechnerHasSoftware $l)
	{
		$this->collRechnerHasSoftwares[] = $l;
		$l->setRechner($this);
	}


	
	public function getRechnerHasSoftwaresJoinSoftware($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseRechnerHasSoftwarePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collRechnerHasSoftwares === null) {
			if ($this->isNew()) {
				$this->collRechnerHasSoftwares = array();
			} else {

				$criteria->add(RechnerHasSoftwarePeer::RECHNER_ID, $this->getId());

				$this->collRechnerHasSoftwares = RechnerHasSoftwarePeer::doSelectJoinSoftware($criteria, $con);
			}
		} else {
									
			$criteria->add(RechnerHasSoftwarePeer::RECHNER_ID, $this->getId());

			if (!isset($this->lastRechnerHasSoftwareCriteria) || !$this->lastRechnerHasSoftwareCriteria->equals($criteria)) {
				$this->collRechnerHasSoftwares = RechnerHasSoftwarePeer::doSelectJoinSoftware($criteria, $con);
			}
		}
		$this->lastRechnerHasSoftwareCriteria = $criteria;

		return $this->collRechnerHasSoftwares;
	}

} 